import net.sevensoft.nocrastinate.model.Context

class ContextController {
  def scaffold = Context    
/*
    def index = { redirect(action:list,params:params) }

    // the delete, save and update actions only accept POST requests
    def allowedMethods = [delete:'POST', save:'POST', update:'POST']

    def list = {
        if(!params.max) params.max = 10
        [ contextList: Context.list( params ) ]
    }

    def show = {
        def context = Context.get( params.id )

        if(!context) {
            flash.message = "Context not found with id ${params.id}"
            redirect(action:list)
        }
        else { return [ context : context ] }
    }

    def delete = {
        def context = Context.get( params.id )
        if(context) {
            context.delete()
            flash.message = "Context ${params.id} deleted"
            redirect(action:list)
        }
        else {
            flash.message = "Context not found with id ${params.id}"
            redirect(action:list)
        }
    }

    def edit = {
        def context = Context.get( params.id )

        if(!context) {
            flash.message = "Context not found with id ${params.id}"
            redirect(action:list)
        }
        else {
            return [ context : context ]
        }
    }

    def update = {
        def context = Context.get( params.id )
        if(context) {
            context.properties = params
            if(!context.hasErrors() && context.save()) {
                flash.message = "Context ${params.id} updated"
                redirect(action:show,id:context.id)
            }
            else {
                render(view:'edit',model:[context:context])
            }
        }
        else {
            flash.message = "Context not found with id ${params.id}"
            redirect(action:edit,id:params.id)
        }
    }

    def create = {
        def context = new Context()
        context.properties = params
        return ['context':context]
    }

    def save = {
        def context = new Context(params)
        if(!context.hasErrors() && context.save()) {
            flash.message = "Context ${context.id} created"
            redirect(action:show,id:context.id)
        }
        else {
            render(view:'create',model:[context:context])
        }
    }
*/
}
